// subgraph isomorphism algorithm: boost_1.55 implementation
// Jeff Eaton 2014

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>

#include <boost/graph/vf2_sub_graph_iso.hpp>
#include <boost/graph/adjacency_list.hpp>

#include "edges.h"

using namespace boost;

// typedef for the Graph data structure
typedef adjacency_list<listS, vecS, undirectedS> Graph;

// boost callback function object that handles the results of the VF2 algorithm
// this is called once for every mapping found
struct vf2_callback {
    
    vf2_callback(const Graph& graph1, const Graph& graph2, Edges &edg) 
      : graph1_(graph1), graph2_(graph2), edg_(edg) {}
    
    template <typename CorrespondenceMap1To2,
              typename CorrespondenceMap2To1>
    bool operator()(CorrespondenceMap1To2 f, CorrespondenceMap2To1) const {
      
		// TODO: convert this to an edge list to allow finding multiple combinations of connected subgraphs (ie both g7s in g8)
		//std::vector<int> vertexList;
		std::vector<std::pair<int, int> > edgeList;
		//int tmp;
		std::pair<int, int> tmp;
		// Print (sub)graph isomorphism map
		/*
		BGL_FORALL_VERTICES_T(v, graph1_, Graph) {
			//std::cout << '(' << get(vertex_index_t(), graph1_, v) << ", " << get(vertex_index_t(), graph2_, get(f, v)) << ") ";
			tmp = get(vertex_index_t(), graph2_, get(f, v));
			vertexList.push_back(tmp);			
			
		}		
		ver_.add(vertexList);
		*/
		
		BGL_FORALL_EDGES_T(e, graph1_, Graph) {
			tmp = std::pair<int, int>(get(vertex_index_t(), graph2_, get(f, e.m_source)), get(vertex_index_t(), graph2_, get(f, e.m_target)));
			//std::cout << get(vertex_index_t(), graph2_, get(f, e.m_source)) << " <-> " << get(vertex_index_t(), graph2_, get(f, e.m_target)) << std::endl;
			edgeList.push_back(tmp);
		}
		edg_.add(edgeList);

		//std::cout << std::endl;

		return true;
    }
    
private:
    const Graph& graph1_;
    const Graph& graph2_;
	Edges& edg_;
};

Graph loadSubgraph(int graphletID);
